package com.lxk.util;

import org.springframework.util.ResourceUtils;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author JohnSoybean
 * @create 2020/4/17 16:39
 * @description 图片url处理工具类
 */
public class ImgUrlUtil {

    /**
     * 将图片字符串分离成url列表
     *
     * @param imgStr
     * @return
     */
    public static List<String> splitUrl(String imgStr) {
        List<String> urlList = new ArrayList<>();
        if (imgStr == null || imgStr.equals("")) {
            return urlList;
        }
        String[] urls = imgStr.split(",");
        for (String url : urls) {
            urlList.add(url);
        }
        return urlList;
    }

    /**
     * 从图片字符串中获取首个图片url
     *
     * @param imgStr
     * @return
     */
    public static String getFirstUrl(String imgStr) {
        if (imgStr == null || imgStr.equals("")) {
            return null;
        }
        int index = imgStr.indexOf(",");
        if (index <= 0) {
            return imgStr;
        } else {
            String url = imgStr.substring(0, index);
            return url;
        }
    }

}
